package com.jeejam.storage.dubbo;

import com.alibaba.dubbo.config.annotation.Service;
import com.jeejam.framework.base.pojo.Pager;
import com.jeejam.storage.pojo.Storage;
import com.jeejam.storage.sdk.api.IStorageService;
import com.jeejam.storage.sdk.dto.StorageDto;
import com.jeejam.storage.service.StorageService;
import com.jeejam.util.ShopBeanBuildUtil;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by JACKEY on 2016/3/26.
 */
@Service(version = "1.0.0")
public class StorageDubboService implements IStorageService {

    @Resource
    private StorageService storageService;

    @Override
    public StorageDto get(int productId, int depotId) {
        return ShopBeanBuildUtil.slmCopyBean(storageService.get(productId, depotId), StorageDto.class);
    }

    @Override
    public List<StorageDto> findByProductId(int productId) {
        return ShopBeanBuildUtil.slmCopyBeanList(storageService.findByProductId(productId), StorageDto.class);
    }

    @Override
    public int counts() {
        return storageService.counts();
    }

    @Override
    public Pager getPager(int currentPage, int pageSize) {
        return storageService.getPager(currentPage, pageSize);
    }

    @Override
    public List<StorageDto> findAllByPage(int currentPage, int pageSize) {
        List<Storage> storageList = storageService.selectAllByPage(currentPage, pageSize);
        return ShopBeanBuildUtil.slmCopyBeanList(storageList, StorageDto.class);
    }

    @Override
    public Pager getPagerByCounts(int counts, int currentPage, int pageSize) {
        return storageService.getPagerByCounts(counts, currentPage, pageSize);
    }

    @Override
    public void deleteById(int id) {
        storageService.deleteById(id);
    }

    @Override
    public StorageDto getById(int id) {
        return ShopBeanBuildUtil.slmCopyBean(storageService.findById(id), StorageDto.class);
    }

    @Override
    public void save(StorageDto storageDto) {
        storageService.save(ShopBeanBuildUtil.slmCopyBean(storageDto, Storage.class));
    }

    @Override
    public void update(StorageDto storageDto) {
        storageService.update(ShopBeanBuildUtil.slmCopyBean(storageDto, Storage.class));
    }
}
